<?php

class Os_Form_OrdemServico extends Zend_Form
{
	protected $_elementos = array();
	public $_cliente = array();
    public function init()
    {
        /* Form Elements & Other Definitions Here ... */
    	$this->getView();
    	$this->setName("ordemServico");
    	$this->setMethod('post');
    	
    	
    	################
    	   	
    	
    	$pedido = new Zend_Form_Element_Text('pedido');
    	$pedido->setLabel("Nº do Pedido")
    	->setFilters(array("StripTags", "StringTrim"))
    	->setRequired(TRUE)
    	->setValidators(array("Digits"));
    	 
    	$this->_elementos['pedido'] = $pedido;
    	
    	$url = $this->_view->url( array('controller' => 'index', 'action' => 'getos', 'module' => 'default'),null,true);
    	$cliente = new Zend_Form_Element_Select('id_cliente');
    	$mapper = new Clientes_Model_ClientesMapper();
    	$modusuario = $mapper->getDbTable()->fillSelectClientes('nome');
    	$cliente->setLabel("Cliente")
    	->setRequired(TRUE)
    	->setAttribs(array('onchange' => 'MySandGet(this.value, "'.$url.'", "html", "#id_reimpressao-element")',))
    	->addMultiOptions($modusuario)
    	;
    	$this->_cliente = $modusuario;
    	$this->_elementos['id_cliente'] = $cliente;
    	
    	$previsao_entrega = new Zend_Form_Element_Text('previsao_entrega');
    	$previsao_entrega->setLabel("Previsão de Entrega")
    	->setFilters(array("StripTags", "StringTrim"))
    	->setRequired(TRUE)
    	->setValidators(array("Date"));
    	 
    	$this->_elementos['previsao_entrega'] = $previsao_entrega;
    	
    	
    }
    
    public function formReimpressao($id_cliente){
    	###
    	
    	$mapper_os = new Os_Model_OsMapper();
    	$modusuario = $mapper_os->getDbTable()->fillSelectOs('id', $id_cliente);
    	if (is_array($modusuario)){
    		array_unshift($modusuario, _("NEW"));
    	}else{
    		$modusuario = array(0=>_("NEW"));
    	}
    	
    	$reimpressao = new Zend_Form_Element_Select('id_reimpressao');
    	$reimpressao->setLabel("Reimpresão da OS")
    	->setRequired(TRUE)
    	->setRegisterInArrayValidator(false)
    	->addMultiOptions($modusuario)
    	;
    	
    	$this->_elementos['id_reimpressao'] = $reimpressao;
    }
    
    public function renderform($submit = "Enviar"){
    	################################
    
    	$enviar = new Zend_Form_Element_Submit("submit");
    	$enviar->setIgnore(true)
    	->setLabel($submit)
    	->removeDecorator('HtmlTag');
    	$this->_elementos["submit"] = $enviar;
    	 
    	$token = new Zend_Form_Element_Hash('token');
    	$token->setSalt('s4a1t-53gur0')
    	->setTimeout(300)
    	->setIgnore(true)
    	->removeDecorator('HtmlTag')
    	->removeDecorator('Label')
    	->addErrorMessage(_('Token provided did not match, session expired. Please reload the form.'));
    	;
    	$this->_elementos['token'] = $token;
    	$this->addElements($this->_elementos);
    	 
    }
    
    public function getmyelement($nome){
    	return $this->_elementos[$nome];
    }


}

